package com.sjd.web.api.farm;

import com.sjd.common.core.domain.AjaxResult;
import com.sjd.common.core.page.TableDataInfo;
import com.sjd.common.utils.PageUtils;
import com.sjd.farm.domain.SjdFarmLandClaimOrder;
import com.sjd.farm.domain.dto.land.FarmLandClaimRequestDTO;
import com.sjd.farm.domain.dto.land.FarmLandUpgradeRequestDTO;
import com.sjd.farm.service.ISjdFarmLandClaimOrderService;
import com.sjd.farm.service.ISjdFarmLandService;
import com.sjd.wx.utils.ThirdSessionHolder;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 微信用户
 *
 * @author male
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/weixin/api/ma/farm/land")
public class WxFarmLandApi {
    private final ISjdFarmLandService landService;
    private final ISjdFarmLandClaimOrderService claimOrderService;

    @GetMapping(value = "/all")
    public AjaxResult farmLandAll() {
        return AjaxResult.success(landService.selectSjdFarmLandList(null));
    }

    @GetMapping(value = "/claimOrder/list/{orderStatus}")
    public TableDataInfo farmLandClaimOrderList(@PathVariable String orderStatus) {
        String allFlag = "ALL";
        SjdFarmLandClaimOrder queryParam = SjdFarmLandClaimOrder.builder()
                .memberId(ThirdSessionHolder.getSjdMemberId()).build();
        if (!allFlag.equals(orderStatus)) {
            queryParam.setOrderStatus(orderStatus);
        }
        PageUtils.startPage();
        List<SjdFarmLandClaimOrder> list = claimOrderService.selectSjdFarmLandClaimOrderList(queryParam);
        return PageUtils.getDataTable(list);
    }

    @PostMapping(value = "/landClaim")
    public AjaxResult farmLandClaim(@Validated @RequestBody FarmLandClaimRequestDTO requestDTO) {
        return claimOrderService.farmLandClaim(requestDTO.getLandId(), requestDTO);
    }

    @PostMapping(value = "/landUpgrade")
    public AjaxResult landUpgrade(@Validated @RequestBody FarmLandUpgradeRequestDTO requestDTO) {
        return claimOrderService.farmLandUpgrade(requestDTO.getClaimOrderId(), requestDTO);
    }

}
